{% extends "base_page_frame.html" %}
{% block headjs %}
    <style type="text/css">
    body {
        background-color: #FFF;
    }
    </style>
    <script>
        $("body").removeClass("indexBody");
    </script>
{% endblock %}
{% load i18n %}
{% load dbapp_tags %}
{% block datalist_content %}
   <div class="index_box">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="left" valign="top">
        <div class="index_min_box" id="personnelModel" style="display: none">
         <div class="index_Personnel_img"><a href="{{ dbapp_url}}personnel/">{% trans '人事' %}</a></div>
         <div class="index_tab_link l">
            <ul class="box_ul">
            </ul>
         </div>
        </div>	</td>
        <td width="10" align="left" valign="top">&nbsp;</td>
        <td align="left" valign="top"><div class="index_min_box" id="iclockModel" style="display: none">
          <div class="index_Device_img"><a href="{{ dbapp_url}}iclock/">{% trans '设备' %}</a></div>
          <div class="index_tab_link l">
            <ul class="box_ul">
            </ul>
          </div>
        </div></td>
        <td align="right" valign="top"><div class="index_max_box" id="queryModel" style="display: none">
          <div class="index_Query_img"><a href="javascript:void(0);">{% trans '查询' %}</a></div>
          <div class="index_tab_link l">
            <ul class="box_ul displayN">
                {% if request.user|HasPerm:"personnel.browse_employee" %}
                <li>
                     <a href="javascript:void(0)" searchfield="employee_num" relgo="/{{request.surl}}worktable/get_search_form/personnel/Employee/" title="{% trans '人员查询' %}">
                     {% trans "人员查询" %}</a>
                </li>
                {% endif %}
                {% if request.user|HasPerm:"personnel.browse_employee" %}
                <li>
                     <a href="javascript:void(0)" searchfield="identitycard" relgo="/{{request.surl}}worktable/get_search_form/personnel/Employee/" title="{% trans '身份证号查询' %}">
                     {% trans "身份证号查询" %}</a>
                </li>
                {% endif %}
                {% if request.user|HasPerm:"personnel.browse_issuecard" %}
                <li>
                     <a href="javascript:void(0)" searchfield="issuecard" relgo="/{{request.surl}}worktable/get_search_form/personnel/IssueCard/" title="{% trans '卡片查询' %}">{% trans "卡片查询" %} </a>
                </li>
                {% endif %}
                {% if request.user|HasPerm:"personnel.browse_department" %}
                <li>
                     <a href="javascript:void(0)" searchfield="department" relgo="/{{request.surl}}worktable/get_search_form/personnel/Department/" title="{% trans '部门查询' %}">{% trans "部门查询" %} </a>
                </li>
                {% endif %}
                {% if "WORKTABLE_ATT_COMMON_SEARCH"|filter_config_option %}
                {% if request.user|HasPerm:"personnel.browse_leavelog" %}
                <li>
                     <a href="javascript:void(0)"  searchfield="leave" relgo="/{{request.surl}}worktable/get_search_form/personnel/LeaveLog/" title="{% trans '离职人员查询' %}">{% trans "离职人员查询" %} </a>
                </li>
                {% endif %}
                {% if request.user|HasPerm:"iclock.browse_transaction" %}
                <li>
                    <a target="_blank" href="/{{request.surl}}page/att/CheckInOut/" title="{% trans '考勤原始数据查询' %}">{% trans "考勤原始数据查询" %} </a>
                </li>
                {% endif %}
                {% if request.user|HasPerm:"personnel.browse_empchange" %}
                <li>
                    <a id ="en_display_show" href="javascript:void(0)" searchfield="empchange" relgo="/{{request.surl}}worktable/get_search_form/personnel/EmpChange/" title="{% trans '员工调动查询' %}">{% trans "员工调动查询" %}</a>
                </li>
                {% endif %}
                {% if request.user|HasPerm:"att.browse_checkexact" %}
                <li>
                    <a href="javascript:void(0)" searchfield="checkexact" relgo="/{{request.surl}}worktable/get_search_form/att/CheckExact/" title="{% trans '补签卡查询' %}">{% trans "补签卡查询" %}</a>
                </li>
                {% endif %}
                {% endif %}
            </ul>
          </div>
        </div></td>
      </tr>
      <tr>
        <td height="90" colspan="4" align="left">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="3" align="left"><div class="index_max_box" id="attModel" style="display: none">
          <div class="index_Attendance_img"><a href="{{ dbapp_url}}att/">{% trans '考勤' %}</a></div>
          <div class="index_tab_link l">
            <ul class="box_ul">
            </ul>
          </div>
        </div></td>
        <td align="right"><div class="index_max_box" id="reportModel" style="display: none">
          <div class="index_Report_img"><a href="/{{request.surl}}page/att/AttReport/">{% trans '考勤报表' %}</a></div>
          <div class="index_tab_link l">
            <ul class="box_ul displayN">
                {% if request.user|HasPerm:"att.calcresultdetail_attreportperms" %}
                  <li><a href="javascript:void(0)" title="{% trans '统计结果详情' %}"  onClick="reportAccess('AttRecAbnormite')">{% trans '统计结果详情' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.earchdayattreport_attreportperms" %}
                  <li><a href="javascript:void(0)" title="{% trans '每日考勤统计表' %}"  onClick="reportAccess('DailyReport')">{% trans '每日考勤统计表' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.attshiftsattreport_attreportperms" %}
                  <li><a href="javascript:void(0)" title="{% trans '考勤明细表' %}"  onClick="reportAccess('AttShifts')">{% trans '考勤明细表' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.calctotalreport_attreportperms" %}
                  <li><a href="javascript:void(0)" title="{% trans '考勤汇总表' %}"  onClick="reportAccess('CalculateReport')">{% trans '考勤汇总表' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.leavetotalreport_attreportperms" %}
                  <li><a href="javascript:void(0)" title="{% trans '请假汇总表' %}"  onClick="reportAccess('LeaveReport')">{% trans '请假汇总表' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.firstlastreport_attreportperms" %}
                    <li><a href="javascript:void(0)" title="{% trans '汇总最早与最晚' %}"  onClick="reportAccess('LEReport')">{% trans '汇总最早与最晚' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.exceptionreport_attreportperms" %}
                    <li><a href="javascript:void(0)" title="{% trans '考勤异常明细表' %}"  onClick="reportAccess('YCReport')">{% trans '考勤异常明细表' %}</a></li>
                {% endif %}
                {% if request.user|HasPerm:"att.deptattsumreport_attreportperms" or request.session.employee %}
                    <li><a href="javascript:void(0)" title="{% trans '部门汇总表' %}" onClick="reportAccess('DeptAttSumReport')">{% trans '部门汇总表' %}</a></li>
                {% endif%}
                {% if request.user|HasPerm:"att.cardtimesreport_attreportperms" %}
                    <li><a href="javascript:void(0)" title="{% trans '打卡详情表' %}"  onClick="reportAccess('CardTimesReport')">{% trans '打卡详情表' %}</a></li>
                {% endif %}
            </ul>
          </div>
        </div></td>
      </tr>
    </table>
  </div>
{% endblock %}
{% block extend_js %}
<script>
    function reportAccess(reportType){
        window.location.href = "/page/att/AttReport/?initLoad="+reportType;
    };
    function afterInit(){
        $(".index_box table td").each(function(){
           if($(this).find('ul>li').length == 0){
               $(this).find('a').attr('href','javascript:void(0);');
               var divCss = $(this).find('>div>div:eq(0)').attr('class');
               if(divCss){
                   var pName = divCss.substring(6);
                   $(this).find('>div>div:eq(0)').css({
                       'background-image':'url(/media/images/abroad_att/'+pName+'_1.png)'
                   });
                   $(this).find('>div>div a').css({
                       'color':'#474b4f'
                   })
               }
           }
           $(this).find('>div').show();
        });
    };
    function initDashboardData(){
        $.ajax({
            url: "{{request.base_url}}/worktable/user_dashboard?type=get",
            type:"GET",
            dataType: "json",
            success: function(callback){
                for(var key in callback){
                    var $model = $("#"+key+"Model");
                    var models = callback[key];
                    $model.find('ul').empty();
                    for(var i=0; i< models.length; i++){
                        var url = ""
                        if(models[i].url !=""){
                            url = models[i].url;
                        }else{
                            url = {{ request.dbapp_url }}+ models[i].app_label +"/"+ models[i].model_name+"/";
                        }
                        var item = '<li><a href="'+url+'" title="'+models[i].verbose_name+'">'+models[i].verbose_name+'</a></li>';
                        $model.find('ul').append(item);
                    }
                }
                $(".box_ul").removeClass("displayN");
                afterInit();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                alert(textStatus);
            }
        });
    }
    function initCommonQuery(surl, dbapp_url){
        var search_fields={
			employee_num:[
				gettext("人员查询"),
				'<td><label  for="id_PIN">'+gettext("人员编号")+'</label></td>'
				+'<td><input type="text" id="id_PIN" maxlength="20"  fieldname="PIN"></td>'
				+'<td><label for="id_EName">'+gettext('姓名')+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="EName" id="id_EName"></td>'
			],
			identitycard:[
				gettext("身份证号查询"),
				'<td><label for="id_identitycard">'+gettext("身份证号码")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="identitycard" id="id_identitycard"></td>'
			],
			device:[
				gettext("考勤设备查询"),
				'<td><label  for="id_alias">'+gettext('设备名称')+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="alias" id="id_alias"></td>'
			],
			leave:[
				gettext("离职人员查询"),
				'<td><label  for="id_UserID__PIN">'+gettext("人员编号")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="UserID__PIN" id="id_UserID__PIN"></td>'
				+'<td><label for="id_UserID__EName" >'+gettext("姓名")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="UserID__EName" id="id_UserID__EName"></td>'
			],
			translog:[
				gettext("考勤原始数据查询"),
				'<td><label class="" for="id_UserID__PIN">'+gettext("人员编号")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="UserID__PIN" id="id_UserID__PIN"></td>'
				+'<td ><label for="id_UserID__EName" >'+gettext("姓名")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="UserID__EName" id="id_UserID__EName"></td>'
			],
			empchange:[
				gettext("员工调动查询"),
				'<td ><label  for="id_UserID__PIN">'+gettext("人员编号")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="UserID__PIN" id="id_UserID__PIN"></td>'
				+'<td ><label for="id_UserID__EName" >'+gettext("姓名")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="UserID__EName" id="id_UserID__EName"></td>'
			],
			issuecard:[
				gettext("卡片查询"),
				'<td ><label  for="id_UserID__PIN">'+gettext("人员编号")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="UserID__PIN" id="id_UserID__PIN"></td>'
				+'<td ><label for="id_UserID__EName" >'+gettext("姓名")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="UserID__EName" id="id_UserID__EName"></td>'
				+'<td ><label for="id_cardno" >'+gettext("卡号")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="cardno" id="id_cardno"></td>'
			],
			department:[
				gettext("部门查询"),
				'<td ><label for="id_code" >'+gettext("部门编号")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="code" id="id_code"></td>'
				+'<td ><label class="" for="id_name">'+gettext("部门名称")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="name" id="id_name"></td>'
			],
			checkexact:[
				gettext("补签卡查询"),
				'<td><label  for="id_UserID__PIN">'+gettext("人员编号")+'</label></td>'
				+'<td><input type="text" maxlength="20" fieldname="UserID__PIN" id="id_UserID__PIN"></td>'
				+'<td><label for="id_UserID__EName" >'+gettext("姓名")+'</label></td>'
				+'<td><input type="text" maxlength="40" fieldname="UserID__EName" id="id_UserID__EName"></td>'
			],
			postmsg:[
			    gettext("发送信息查询"),
				'<td><label for="id_msg_type">'+gettext("消息类型")+'</label></td>'
				+'<td><input type="text" maxlength="10" fieldname="msg_type" id="id_msg_type"></td>'
				+'<td><label for="id_msg_title">'+gettext(" 信息标题")+'</label></td>'
				+'<td><input type="text" maxlength="100" fieldname="msg_title" if="id_msg_title"></td>'
			]
		}
        var s_900=["employee_num","identitycard","device","translog"];
        $("#queryModel").find("a[relgo]").click(function(event){
			var href=$(this).attr("relgo");
			var key_search=$(this).attr("searchfield");
			var t_search_fields=search_fields[key_search];
			var d=new Date();
			if(href.indexOf("?")==-1){
				href=href+"?stamp="+d.getTime();
			}else{
				href=href+"&stamp="+d.getTime();
			}
			$.ajax({
				type:"GET",
				dataType:"html",
				async:false,
				url:href,
				success:function(msg){
					if($("#id_opt_message").length==0){
						$("body").append("<div id='id_opt_message' style='overflow:hidden'></div>");
					}
					var $msg_dialog=$("#id_opt_message");
					$msg_dialog.html(msg);
					$("#id_title",$msg_dialog).html(t_search_fields[0]);
					$("#id_form_search tr",$msg_dialog).prepend(t_search_fields[1]);
					for(var i in s_900){
					    if (key_search==s_900[i]){
							if($msg_dialog.width()>900){
								$msg_dialog.width(900);
							}
						}
					}
					$msg_dialog.dialog({
						on_load:function(obj){
							var $overlay=obj.target.getOverlay();
							$overlay.find("input[type!=hidden]:first").focus().select();
							$overlay.find("input").keydown(function(event){//按回车键直接查询
								if(event.keyCode==13)
								{
								   $overlay.find("#id_header_search").click();
								}

							});
							//$overlay.width($overlay.width());
					}});
					setTimeout(function(){
						$msg_dialog.width($msg_dialog.width());
						//$msg_dialog.parent(".contentWrap").css("overflow","hidden");
					},1000);
				},
				error:function(one,two,three){
					alert(gettext("服务器加载数据失败,请重试!"));
				}
			});
			return false;
		});
    }
    $(function(){
        $('.tabBody').remove();
        $('.docking_bg_l').remove();
        initDashboardData();
        var surl="{{ request.surl }}";
        var dbapp_url="{{ request.dbapp_url }}";
        initCommonQuery(surl, dbapp_url)
    });
</script>
{% endblock %}